package com.example.demo.Entity.User;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.example.demo.Entity.LoginUser.LoginUser;
import com.example.demo.Entity.Role.Role;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author Wu
 * @since 2025-04-04 04:46:55
 */
@Data
@AllArgsConstructor
@RequiredArgsConstructor
public class User implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    private String username;

    private String password;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")  // 处理表单时间格式
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastLoginTime;

    private String role;

    public UserDetails GetUserDetail() {
        Role Role = new Role(role);
        List<Role> Roles = new ArrayList<>();
        Roles.add(Role);
        return new LoginUser(this.username, this.password, Roles);
    }
}
